﻿using Microsoft.AspNetCore.Mvc;
using Zhp.Api.Attributes;
using Zhp.IService.Formula;
using Zhp.Model.Common;
using Zhp.Model.Formula;

namespace Zhp.Api.Controllers.Formula
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiGroup(GroupName = ApiGroupEnum.Formula)]
    [SeedMenu(MenuGroup = ApiGroupEnum.Formula, Name = "配置公式", Order = 1, RouterName = "formuladata", WebFilePath = "formula/formulaData/index", Icon = "fx")]
    public class FormulaDataController : ControllerBase
    {
        private readonly IFormulaDataService _formulaDataService;
        public FormulaDataController(IFormulaDataService formulaDataService)
        {
            _formulaDataService = formulaDataService;
        }

        [HttpPost]
        [SeedList("公式列表", "配置公式", ApiGroupEnum.Formula)]
        public async Task<PageRet<FormulaDataModel>> Query(FormulaDataSearch search)
        {
            var list = await _formulaDataService.Query(search);

            return new PageRet<FormulaDataModel>
            {
                DataList = list,
                TotalCount = search.TotalCount,
            };
        }

        [HttpPost]
        [SeedButton("新增", "公式列表", "配置公式", ApiGroupEnum.Formula, ["/api/FormulaVariable/QueryFormulaVariable"])]
        public async Task<bool> Create(FormulaDataEdit p)
        {
            return await _formulaDataService.Create(p);
        }

        [HttpPut()]
        [SeedButton("修改", "公式列表", "配置公式", ApiGroupEnum.Formula)]
        public async Task<bool> Update(FormulaDataEdit p)
        {
            return await _formulaDataService.Update(p);
        }

        [HttpDelete("{id}")]
        [SeedButton("删除", "公式列表", "配置公式", ApiGroupEnum.Formula)]
        public async Task<bool> Delete(long id)
        {
            return await _formulaDataService.Delete(id);
        }
    }
}
